#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <list>
#include <vector>
#include <algorithm>
#include <array>
#include <time.h>
#include <queue>
using namespace std;

#include "list.h"
#include "vector.h"
// 打印链表(使用const迭代器)
void print_list(const apex::list<int> &lt)
{
	apex::list<int>::const_iterator it = lt.begin();
	while (it != lt.end())
	{
		cout << *it << " ";
		it++;
	}
	cout << endl;
}

// 无参构造  尾插  迭代器
void test_list1()
{
	apex::list<int> lt;
	lt.push_back(1);
	lt.push_back(2);
	lt.push_back(3);
	lt.push_back(4);

	// 正向迭代器
	apex::list<int>::iterator it = lt.begin();
	while (it != lt.end())
	{
		*it *= 2;
		cout << *it << " ";
		it++;
	}
	cout << endl;
	// 反向迭代器
	apex::list<int>::riterator rit = lt.rbegin();
	while (rit != lt.rend())
	{
		*rit *= 2;
		cout << *rit << " ";
		rit++;
	}
	cout << endl;
}

// 打印函数
void test_list2()
{
	apex::list<int> lt;
	lt.push_back(2);
	lt.push_back(4);
	lt.push_back(6);
	lt.push_back(8);

	print_list(lt);
}

// 创建日期类 测试成员访问运算符
struct Date
{
	int _year;
	int _month;
	int _day;

	Date(int year = 1, int month = 1, int day = 1)
		: _year(year), _month(month), _day(day)
	{
	}
};
void test_list3()
{
	apex::list<Date> lt;
	lt.push_back(Date(2023, 7, 21));
	lt.push_back(Date(2023, 7, 22));
	lt.push_back(Date(2023, 7, 23));

	apex::list<Date>::iterator it = lt.begin();
	while (it != lt.end())
	{
		cout << it->_year << "-" << it->_month << "-" << it->_day << endl;
		it++;
	}
	cout << endl;
}

// 拷贝构造函数
void test_list4()
{
	apex::list<int> lt1;
	lt1.push_back(1);
	lt1.push_back(2);
	lt1.push_back(3);

	apex::list<int> lt2(lt1);
	for (auto e : lt2)
		cout << e << " ";
}

// 清空函数
void test_list5()
{
	apex::list<int> lt;
	lt.push_back(1);
	lt.push_back(2);
	lt.push_back(3);

	print_list(lt);
	lt.clear();
	print_list(lt);
}
int main()
{
	test_list1();
	return 0;
}